package haff;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.KeyStore.Entry;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Enumeration;
import java.util.HashMap;

import javax.crypto.SecretKey;

public class Keyer {
	static HashMap<String,String> map=new HashMap<>();
	public static void writeAsKeyStore(HashMap<String,String> map,String path,String alias,String password) {
		try(InputStream in=Files.newInputStream(Paths.get(path))){
			KeyStore ks=KeyStore.getInstance("JKS");
			ks.load(in, password.toCharArray());
			
			//Set<Attribute> attr=new Set<>();
			PrivateKey pk=(PrivateKey) ks.getKey(alias, password.toCharArray());
			//ks.setEntry(alias ,new KeyStore.PrivateKeyEntry(pk, null, ),) null);
		} catch (IOException | KeyStoreException | NoSuchAlgorithmException | CertificateException | UnrecoverableKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String...args) {
		Keyer.writeAsKeyStore(map, "src\\haff\\.keystore","mykey", "123456");
	}
}
